package com.example.demo.day0301;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class DemoOutPutStreamWriter {
    public static void main(String[] args) {
        try {
            DemoOutPutStreamWriter.testDemoOutPutStreamWriter();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void testDemoOutPutStreamWriter() throws Exception {
        FileOutputStream fs = new FileOutputStream("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt6.txt");
        //字节输出流

        OutputStreamWriter ow = new OutputStreamWriter(fs,"UTF-8");
        //将字节输出流传换成字符输入流
//        OutputStreamWriter ow = new OutputStreamWriter(fs,"GBK");
        //注意，在转换字符流的时候，设置的字符集编码要与读取的文件的数据的编码一致


        ow.write("转换");//把数据写到内存
        ow.flush();//把数据刷到硬盘

        ow.close();
        fs.close();//先开后关

    }
}
